/**
 * 用户模块
 */

var express = require('express');
var router = express.Router();

const user = require("../controller/user");

const auth = require("../controller/auth")

/* GET users listing. */
// router.get('/', function(req, res, next) {
//   res.send('respond with a resource');
// });


// 注册
router.post("/register",user.register);
//登录
router.post("/login",user.login)
//退出登录
router.get("/logout",auth.isLogin,user.logout)
//查询用户数量
router.get("/count",user.getCount)
//查询用户
router.get("/search",user.search)

router.get("/:id",auth.isLogin,auth.isSelfOfAdmin,user.find);

router.get("/",auth.isLogin,auth.isAdmin,user.findAll);

//修改个人信息
router.patch("/change-info",auth.isLogin,user.changeInfo)
//修改密码
router.patch("/change-password",auth.isLogin,user.changePassword)
//重置密码
router.patch("/reset-password/:id",auth.isLogin,user.resetPassword)


router.post("/",auth.isLogin,auth.isAdmin,user.add);

router.put("/:id",auth.isLogin,auth.isAdmin,user.update);

router.delete("/:id",auth.isLogin,auth.isAdmin,user.remove);


module.exports = router;
